package com.leesche.zcsp.node.web.controller.web.v2.admin;

import com.leesche.zcsp.node.web.service.privilege.PrivilegeService;
import com.leesche.zcsp.node.web.vo.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by kaider on 2016/12/29.
 * v2版本获取登录用户信息
 */
public class WebAdminController {
    private final static Logger LOGGER = LoggerFactory.getLogger(WebAdminController.class);

    @Autowired
    private PrivilegeService privilegeService;

    //用户获取
    public Long getAdminId(){
        Principal principal = privilegeService.getCurrentPrincipal();
        Long adminId;
       if(principal.getParentid()==1||principal.getNtype()==4){
            adminId = principal.getUserid();
        }else{
            adminId = principal.getParentid();
        }
        LOGGER.info("用户ID：",adminId);
        return adminId;
    }

    //商户号
    public String getBusinessNo(){
        Principal principal = privilegeService.getCurrentPrincipal();
        String BusinessNo = principal.getBusinessno();
        return BusinessNo;
    }

    //工厂获取
    public Long getFactoryAdminId(){
        Principal principal = privilegeService.getCurrentPrincipal();
        Long adminId;
        if(principal.getNtype()==2 || principal.getNtype()==3){
            if(principal.getParentid()==1){
                adminId = principal.getUserid();
            }else{
                adminId = principal.getParentid();
            }
        }else{
            adminId=null;
        }
        LOGGER.info("工厂用户ID：",adminId);
//        System.out.println("工厂用户ID："+adminId);
        return adminId;
    }

    //用户简码
    public String getUserShortCode(){
        Principal principal = privilegeService.getCurrentPrincipal();
        String userShortCode = principal.getUserShortCode();
        return userShortCode;
    }

}
